package com.atguigu.thread;

import com.sun.org.glassfish.external.amx.MBeanListener;

import java.util.concurrent.*;

public class CallableTest {


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CallImpl call = new CallImpl();
        CallImpl2 call2 = new CallImpl2();
        FutureTask<String> futureTask = new FutureTask<String>(call);
        FutureTask<String> futureTask2 = new FutureTask<String>(call2);

        new Thread(futureTask).start();
        TimeUnit.SECONDS.sleep(2);
        System.out.println("main------");
        new Thread(futureTask2).start();

        System.out.println(futureTask.get());
//        System.out.println("main------");

    }
}


class CallImpl implements Callable<String>{

    @Override
    public String call() throws Exception {
        System.out.println("this is callable");
        return "ending";
    }
}
class CallImpl2 implements Callable<String>{

    @Override
    public String call() throws Exception {
        System.out.println("this is callable2");
        return "ending";
    }
}